//
//  HomeViewController.m
//  solarMan
//
//  Created by 范桂盛 on 2016/12/13.
//  Copyright © 2016年 solar. All rights reserved.
//

#import "HomeViewController.h"
#import <Masonry.h>
#import "CommonDefines.h"
#import <projA/AViewController.h>
#import <projB/BViewController.h>

@interface HomeViewController ()
@property (nonatomic, strong) UIButton *triggerButton;
@property (nonatomic, strong) UIButton *addButton;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"Home";
    
    UIButton *triggerButton = [UIButton new];
    [triggerButton setTitle:@"Push BViewController" forState:UIControlStateNormal];
    [triggerButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [triggerButton addTarget:self action:@selector(triggerButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.triggerButton = triggerButton;
    [self.view addSubview:self.triggerButton];
    [self.triggerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(200, 30));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.centerY.mas_equalTo(self.view.mas_centerY);
    }];
    
    UIImageView *imageView = [UIImageView new];
    imageView.image = [UIImage imageNamed:@"v_personal"];
    [self.view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(triggerButton.mas_top).offset(-20);
    }];
    
    triggerButton = [UIButton new];
    [triggerButton setTitle:@"Push AViewController" forState:UIControlStateNormal];
    [triggerButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [triggerButton addTarget:self action:@selector(addButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.addButton = triggerButton;
    [self.view addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(200, 30));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(self.triggerButton.mas_bottom).offset(50);
    }];
    
    
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSString *rigntItemTitle = @"Login";
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:rigntItemTitle style:UIBarButtonItemStylePlain target:self action:@selector(loginButtonClick)];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)addButtonClick
{
    AViewController *vc = [AViewController new];
    [self.navigationController pushViewController:vc animated:YES];
    
    return;
}

- (void)triggerButtonClick
{
    
    BViewController *vc = [BViewController new];
    [self.navigationController pushViewController:vc animated:YES];
    
    return;
}

- (void)loginButtonClick
{

}
@end
